package com.chalk.common.exception;


import com.chalk.common.util.ResultCode;

/**
 * 描述：服务统一异常
 *
 * @author He Yong
 * @version 1.0
 * @since 2018/2/5
 */
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 655220847117448981L;
    /**
     * 异常码
     */
    protected int code;

    /**
     * 异常信息
     */
    protected String msg;

    public ServiceException() {
        super();
    }

    public ServiceException(ResultCode resultCode) {
        super(resultCode.msg());
        this.code = resultCode.code();
        this.msg = resultCode.msg();
    }

    public ServiceException(int code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public ServiceException(int code, String msgFormat, Object... args) {
        super(String.format(msgFormat, args));
        this.code = code;
        this.msg = String.format(msgFormat, args);
    }

    public ServiceException(String msg) {
        super(msg);
    }

    public ServiceException(String msgFormat, Object... args) {
        super(String.format(msgFormat, args));
    }

    public ServiceException(Throwable cause) {
        super(cause);
    }

    public ServiceException(String msg, Throwable cause) {
        super(msg, cause);
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
